/**
 * 
 */
var WindMap = (function () {
    // 初始化
 
    function WindMap(options) { // 属性
    	this.visible=false;
    	this.map=options.map;
    	this.dragStarted = false;
		this.windy={};
    	this.canvas = document.getElementById(options.canvas);//'windmap'
    	this.init();
    }
    WindMap.prototype.init = function () {
    	var that=this;
        
        this.map.on('moveend', function(){
        	if(that.visible===true){
        		that.start();
        	}
        });
        this.map.on("pointerdrag", function (ev) {        	 
            if (!that.dragStarted) {
                $("#windmap").css("visibility", "hidden");
                that.dragStarted = true;
            }
        });
        
        fetch('data/windata/static.json').then(function (response) {
            return response.json();
        }).then(function (json) {
        	that.windy = new Windy({
                canvas: that.canvas,
                data: json
            });
        	//that.start();
        });
       
         
    };
    
    WindMap.prototype.stop=function()
    {
    	this.visible=false;
    	if (this.windy) {
    		this.windy.stop();
    	}
    	/*
    	this.map.interactions=ol.interaction.defaults({
            altShiftDragRotate: false,
            rotate: false
        });*/
    }
    WindMap.prototype.start=function()
    {
    	var that=this;
    	this.visible=true;
    	if (that.windy) {
    		that.dragStarted = false;    	 
            $("#windmap").css("visibility", "visible");
            if (!that.visible || !that.windy) {
                return;
            }
            //that.windy.stop();
            var mapSize = that.map.getSize();
            var extent = that.map.getView().calculateExtent(mapSize);
            extent = ol.proj.transformExtent(extent, 'EPSG:3857', 'EPSG:4326');
           
            that.canvas.width = mapSize[0];
            that.canvas.height = mapSize[1];
            console.info(extent);
            that.windy.start([[0, 0], [that.canvas.width, that.canvas.height]],
            		that.canvas.width, that.canvas.height, [[extent[0], extent[1]],
            [extent[2], extent[3]]]);
    	}
    	/*
    	this.map.interactions=ol.interaction.defaults({
            altShiftDragRotate: false,
            rotate: false
        });*/
    }
    //
    // 初始化
   
 
    // 返回
    return WindMap;
})();
 